package com.my.bigsite.modules.sys.web;

import javax.servlet.http.HttpSession;

import org.activiti.engine.IdentityService;
import org.activiti.engine.identity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.my.bigsite.common.util.UserUtil;
import com.my.bigsite.common.web.BaseController;


@Controller
public class loginController  extends BaseController{
	@Autowired
	private IdentityService identityService;
	
	@RequestMapping(value = "/sys/login",method = RequestMethod.GET)
	public String loginController() {
		 return "modules/sys/login";
	}
	@RequestMapping(value = "/sys/login",method = RequestMethod.POST)
	public String loginSubmit(String username,String password,HttpSession httpSession) {
		Boolean flag=identityService.checkPassword(username, password);
	    logger.debug("提交登陆:"+identityService.toString()+"密码验证结果:"+flag);
	    if(flag){
	    	  // read user from database
            User user = identityService.createUserQuery().userId(username).singleResult();
	        UserUtil.saveUserToSession(httpSession, user);
	    	return "redirect:/sys/index";
	    }else{
		 return "modules/sys/login";
	    }
	}
}
